﻿//
// This file is part of AVSReflector project
// Copyright (C) 2011 Yuan Pengfei
//

using System;
using System.Collections.Generic;
using System.Text;

namespace AVSReflector.Core
{
    enum VLCTableType
    {
        Intra, Inter, Chroma
    }

    class VLCTable
    {
        VLCTableType type;
        int id;

        static int[][] intraLevel;
        static int[][] intraRun;
        static int[][] interLevel;
        static int[][] interRun;
        static int[][] chromaLevel;
        static int[][] chromaRun;

        int[] level;
        int[] run;

        public VLCTable(VLCTableType t, int i = 0)
        {
            type = t;
            id = i;
            Update();
        }

        public void SetType(VLCTableType t)
        {
            type = t;
            Update();
        }

        public void SetID(int i)
        {
            id = i;
            Update();
        }

        public int K()
        {
            if (id == 0 && type == VLCTableType.Inter)
                return 3;
            if (type == VLCTableType.Chroma)
            {
                if (id == 2 || id == 3)
                    return 1;
                if (id == 1 || id == 4)
                    return 0;
            }
            return 2;
        }

        public uint EOB()
        {
            uint ret = 0xffffffffu;
            if (id == 0)
                return ret;
            if (type == VLCTableType.Intra)
            {
                if (id <= 3)
                    ret = 8;
                if (id == 4)
                    ret = 6;
                if (id >= 5)
                    ret = 0;
            }
            if (type == VLCTableType.Inter)
            {
                if (id <= 4)
                    ret = 2;
                if (id >= 5)
                    ret = 0;
            }
            if (type == VLCTableType.Chroma)
            {
                if (id == 1 || id >= 3)
                    ret = 0;
                if (id == 2)
                    ret = 2;
            }
            return ret;
        }

        public int MaxRun()
        {
            int ret = -1;
            if (type == VLCTableType.Intra)
            {
                switch (id)
                {
                    case 0:
                        ret = 22;
                        break;
                    case 1:
                        ret = 14;
                        break;
                    case 2:
                        ret = 9;
                        break;
                    case 3:
                        ret = 6;
                        break;
                    case 4:
                        ret = 4;
                        break;
                    case 5:
                        ret = 2;
                        break;
                    case 6:
                        ret = 1;
                        break;
                }
            }
            if (type == VLCTableType.Inter)
            {
                switch (id)
                {
                    case 0:
                        ret = 25;
                        break;
                    case 1:
                        ret = 18;
                        break;
                    case 2:
                        ret = 13;
                        break;
                    case 3:
                        ret = 9;
                        break;
                    case 4:
                        ret = 6;
                        break;
                    case 5:
                        ret = 4;
                        break;
                    case 6:
                        ret = 3;
                        break;
                }
            }
            if (type == VLCTableType.Chroma)
            {
                switch (id)
                {
                    case 0:
                        ret = 24;
                        break;
                    case 1:
                        ret = 19;
                        break;
                    case 2:
                        ret = 10;
                        break;
                    case 3:
                        ret = 7;
                        break;
                    case 4:
                        ret = 4;
                        break;
                }
            }
            return ret;
        }

        // refAbsLevel's lookup index is run, not trans_coefficient
        public int RefAbsLevel(uint r)
        {
            int ret = 1;
            if (type == VLCTableType.Intra)
            {
                if (id == 0)
                {
                    if (r == 0) ret = 4;
                    else if (r <= 4) ret = 3;
                    else if (r <= 22) ret = 2;
                }
                if (id == 1)
                {
                    if (r == 0) ret = 7;
                    else if (r <= 2) ret = 4;
                    else if (r <= 7) ret = 3;
                    else if (r <= 14) ret = 2;
                }
                if (id == 2)
                {
                    if (r == 0) ret = 10;
                    else if (r == 1) ret = 6;
                    else if (r <= 3) ret = 4;
                    else if (r <= 6) ret = 3;
                    else if (r <= 9) ret = 2;
                }
                if (id == 3)
                {
                    if (r == 0) ret = 13;
                    else if (r == 1) ret = 7;
                    else if (r == 2) ret = 5;
                    else if (r == 3) ret = 4;
                    else if (r == 4) ret = 3;
                    else if (r <= 6) ret = 2;
                }
                if (id == 4)
                {
                    if (r == 0) ret = 18;
                    else if (r == 1) ret = 8;
                    else if (r == 2) ret = 4;
                    else if (r <= 4) ret = 2;
                }
                if (id == 5)
                {
                    if (r == 0) ret = 22;
                    else if (r == 1) ret = 7;
                    else if (r == 2) ret = 3;
                }
                if (id == 6)
                {
                    if (r == 0) ret = 27;
                    else if (r == 1) ret = 4;
                }
            }
            if (type == VLCTableType.Inter)
            {
                if (id == 0)
                {
                    if (r == 0) ret = 4;
                    else if (r == 1) ret = 3;
                    else if (r <= 25) ret = 2;
                }
                if (id == 1)
                {
                    if (r == 0) ret = 5;
                    else if (r == 1) ret = 4;
                    else if (r <= 6) ret = 3;
                    else if (r <= 18) ret = 2;
                }
                if (id == 2)
                {
                    if (r == 0) ret = 7;
                    else if (r == 1) ret = 5;
                    else if (r <= 3) ret = 4;
                    else if (r <= 6) ret = 3;
                    else if (r <= 13) ret = 2;
                }
                if (id == 3)
                {
                    if (r == 0) ret = 10;
                    else if (r == 1) ret = 6;
                    else if (r == 2) ret = 5;
                    else if (r == 3) ret = 4;
                    else if (r <= 5) ret = 3;
                    else if (r <= 9) ret = 2;
                }
                if (id == 4)
                {
                    if (r == 0) ret = 13;
                    else if (r == 1) ret = 7;
                    else if (r == 2) ret = 5;
                    else if (r == 3) ret = 4;
                    else if (r == 4) ret = 3;
                    else if (r <= 6) ret = 2;
                }
                if (id == 5)
                {
                    if (r == 0) ret = 17;
                    else if (r == 1) ret = 8;
                    else if (r == 2) ret = 4;
                    else if (r == 3) ret = 3;
                    else if (r == 4) ret = 2;
                }
                if (id == 6)
                {
                    if (r == 0) ret = 22;
                    else if (r == 1) ret = 6;
                    else if (r == 2) ret = 3;
                    else if (r == 3) ret = 2;
                }
            }
            if (type == VLCTableType.Chroma)
            {
                if (id == 0)
                {
                    if (r == 0) ret = 5;
                    else if (r == 1) ret = 3;
                    else if (r <= 24) ret = 2;
                }
                if (id == 1)
                {
                    if (r == 0) ret = 6;
                    else if (r == 1) ret = 4;
                    else if (r <= 4) ret = 3;
                    else if (r <= 19) ret = 2;
                }
                if (id == 2)
                {
                    if (r == 0) ret = 10;
                    else if (r == 1) ret = 6;
                    else if (r <= 3) ret = 4;
                    else if (r <= 5) ret = 3;
                    else if (r <= 10) ret = 2;
                }
                if (id == 3)
                {
                    if (r == 0) ret = 14;
                    else if (r == 1) ret = 7;
                    else if (r == 2) ret = 4;
                    else if (r <= 4) ret = 3;
                    else if (r <= 7) ret = 2;
                }
                if (id == 4)
                {
                    if (r == 0) ret = 20;
                    else if (r == 1) ret = 7;
                    else if (r == 2) ret = 3;
                    else if (r <= 4) ret = 2;
                }
            }
            return ret;
        }

        public int Level(uint n)
        {
            return level[n];
        }

        public int Run(uint n)
        {
            return run[n];
        }

        void Update()
        {
            if (type == VLCTableType.Intra)
                UpdateIntra();
            if (type == VLCTableType.Inter)
                UpdateInter();
            if (type == VLCTableType.Chroma)
                UpdateChroma();
        }

        void UpdateIntra()
        {
            if (intraLevel == null)
                intraLevel = new int[7][];
            if (intraRun == null)
                intraRun = new int[7][];
            if (intraLevel[id] == null)
            {
                intraLevel[id] = new int[60];
                #region id == 0
                if (id == 0)
                {
                    intraLevel[id][0] = 1;
                    intraLevel[id][2] = 1;
                    intraLevel[id][4] = 1;
                    intraLevel[id][6] = 1;
                    intraLevel[id][8] = 1;
                    intraLevel[id][10] = 1;
                    intraLevel[id][12] = 1;
                    intraLevel[id][14] = 1;
                    intraLevel[id][16] = 1;
                    intraLevel[id][18] = 1;
                    intraLevel[id][20] = 1;
                    intraLevel[id][24] = 1;
                    intraLevel[id][26] = 1;
                    intraLevel[id][28] = 1;
                    intraLevel[id][30] = 1;
                    intraLevel[id][34] = 1;
                    intraLevel[id][36] = 1;
                    intraLevel[id][40] = 1;
                    intraLevel[id][42] = 1;
                    intraLevel[id][46] = 1;
                    intraLevel[id][48] = 1;
                    intraLevel[id][52] = 1;
                    intraLevel[id][56] = 1;
                    intraLevel[id][22] = 2;
                    intraLevel[id][32] = 2;
                    intraLevel[id][44] = 2;
                    intraLevel[id][50] = 2;
                    intraLevel[id][54] = 2;
                    intraLevel[id][38] = 3;
                }
                #endregion
                #region id == 1
                if (id == 1)
                {
                    intraLevel[id][0] = 1;
                    intraLevel[id][2] = 1;
                    intraLevel[id][6] = 1;
                    intraLevel[id][9] = 1;
                    intraLevel[id][11] = 1;
                    intraLevel[id][13] = 1;
                    intraLevel[id][19] = 1;
                    intraLevel[id][21] = 1;
                    intraLevel[id][23] = 1;
                    intraLevel[id][29] = 1;
                    intraLevel[id][31] = 1;
                    intraLevel[id][37] = 1;
                    intraLevel[id][43] = 1;
                    intraLevel[id][47] = 1;
                    intraLevel[id][57] = 1;
                    intraLevel[id][4] = 2;
                    intraLevel[id][17] = 2;
                    intraLevel[id][25] = 2;
                    intraLevel[id][33] = 2;
                    intraLevel[id][39] = 2;
                    intraLevel[id][45] = 2;
                    intraLevel[id][49] = 2;
                    intraLevel[id][51] = 2;
                    intraLevel[id][15] = 3;
                    intraLevel[id][35] = 3;
                    intraLevel[id][53] = 3;
                    intraLevel[id][27] = 4;
                    intraLevel[id][41] = 5;
                    intraLevel[id][55] = 6;
                }
                #endregion
                #region id == 2
                if (id == 2)
                {
                    intraLevel[id][0] = 1;
                    intraLevel[id][2] = 2;
                    intraLevel[id][6] = 3;
                    intraLevel[id][13] = 4;
                    intraLevel[id][17] = 5;
                    intraLevel[id][27] = 6;
                    intraLevel[id][35] = 7;
                    intraLevel[id][45] = 8;
                    intraLevel[id][55] = 9;
                    intraLevel[id][4] = 1;
                    intraLevel[id][11] = 2;
                    intraLevel[id][21] = 3;
                    intraLevel[id][33] = 4;
                    intraLevel[id][49] = 5;
                    intraLevel[id][9] = 1;
                    intraLevel[id][23] = 2;
                    intraLevel[id][37] = 3;
                    intraLevel[id][15] = 1;
                    intraLevel[id][29] = 2;
                    intraLevel[id][51] = 3;
                    intraLevel[id][19] = 1;
                    intraLevel[id][39] = 2;
                    intraLevel[id][25] = 1;
                    intraLevel[id][43] = 2;
                    intraLevel[id][31] = 1;
                    intraLevel[id][53] = 2;
                    intraLevel[id][41] = 1;
                    intraLevel[id][47] = 1;
                    intraLevel[id][57] = 1;
                }
                #endregion
                #region id == 3
                if (id == 3)
                {
                    intraLevel[id][0] = 1;
                    intraLevel[id][2] = 2;
                    intraLevel[id][4] = 3;
                    intraLevel[id][9] = 4;
                    intraLevel[id][11] = 5;
                    intraLevel[id][17] = 6;
                    intraLevel[id][21] = 7;
                    intraLevel[id][25] = 8;
                    intraLevel[id][33] = 9;
                    intraLevel[id][39] = 10;
                    intraLevel[id][45] = 11;
                    intraLevel[id][55] = 12;
                    intraLevel[id][6] = 1;
                    intraLevel[id][13] = 2;
                    intraLevel[id][19] = 3;
                    intraLevel[id][29] = 4;
                    intraLevel[id][35] = 5;
                    intraLevel[id][47] = 6;
                    intraLevel[id][15] = 1;
                    intraLevel[id][27] = 2;
                    intraLevel[id][41] = 3;
                    intraLevel[id][57] = 4;
                    intraLevel[id][23] = 1;
                    intraLevel[id][37] = 2;
                    intraLevel[id][53] = 3;
                    intraLevel[id][31] = 1;
                    intraLevel[id][51] = 2;
                    intraLevel[id][43] = 1;
                    intraLevel[id][49] = 1;
                }
                #endregion
                #region id == 4
                if (id == 4)
                {
                    intraLevel[id][0] = 1;
                    intraLevel[id][2] = 2;
                    intraLevel[id][4] = 3;
                    intraLevel[id][7] = 4;
                    intraLevel[id][9] = 5;
                    intraLevel[id][11] = 6;
                    intraLevel[id][15] = 7;
                    intraLevel[id][17] = 8;
                    intraLevel[id][21] = 9;
                    intraLevel[id][23] = 10;
                    intraLevel[id][29] = 11;
                    intraLevel[id][33] = 12;
                    intraLevel[id][35] = 13;
                    intraLevel[id][43] = 14;
                    intraLevel[id][47] = 15;
                    intraLevel[id][49] = 16;
                    intraLevel[id][57] = 17;
                    intraLevel[id][13] = 1;
                    intraLevel[id][19] = 2;
                    intraLevel[id][27] = 3;
                    intraLevel[id][31] = 4;
                    intraLevel[id][37] = 5;
                    intraLevel[id][45] = 6;
                    intraLevel[id][55] = 7;
                    intraLevel[id][25] = 1;
                    intraLevel[id][41] = 2;
                    intraLevel[id][51] = 3;
                    intraLevel[id][39] = 1;
                    intraLevel[id][53] = 1;
                }
                #endregion
                #region id == 5
                if (id == 5)
                {
                    intraLevel[id][1] = 1;
                    intraLevel[id][3] = 2;
                    intraLevel[id][5] = 3;
                    intraLevel[id][7] = 4;
                    intraLevel[id][9] = 5;
                    intraLevel[id][11] = 6;
                    intraLevel[id][13] = 7;
                    intraLevel[id][15] = 8;
                    intraLevel[id][17] = 9;
                    intraLevel[id][19] = 10;
                    intraLevel[id][23] = 11;
                    intraLevel[id][25] = 12;
                    intraLevel[id][27] = 13;
                    intraLevel[id][31] = 14;
                    intraLevel[id][33] = 15;
                    intraLevel[id][37] = 16;
                    intraLevel[id][41] = 17;
                    intraLevel[id][45] = 18;
                    intraLevel[id][49] = 19;
                    intraLevel[id][51] = 20;
                    intraLevel[id][55] = 21;
                    intraLevel[id][21] = 1;
                    intraLevel[id][29] = 2;
                    intraLevel[id][35] = 3;
                    intraLevel[id][43] = 4;
                    intraLevel[id][47] = 5;
                    intraLevel[id][53] = 6;
                    intraLevel[id][39] = 1;
                    intraLevel[id][57] = 2;
                }
                #endregion
                #region id == 6
                if (id == 6)
                {
                    intraLevel[id][1] = 1;
                    intraLevel[id][3] = 2;
                    intraLevel[id][5] = 3;
                    intraLevel[id][7] = 4;
                    intraLevel[id][9] = 5;
                    intraLevel[id][11] = 6;
                    intraLevel[id][13] = 7;
                    intraLevel[id][15] = 8;
                    intraLevel[id][17] = 9;
                    intraLevel[id][19] = 10;
                    intraLevel[id][21] = 11;
                    intraLevel[id][23] = 12;
                    intraLevel[id][25] = 13;
                    intraLevel[id][27] = 14;
                    intraLevel[id][29] = 15;
                    intraLevel[id][31] = 16;
                    intraLevel[id][35] = 17;
                    intraLevel[id][37] = 18;
                    intraLevel[id][39] = 19;
                    intraLevel[id][41] = 20;
                    intraLevel[id][43] = 21;
                    intraLevel[id][47] = 22;
                    intraLevel[id][49] = 23;
                    intraLevel[id][51] = 24;
                    intraLevel[id][53] = 25;
                    intraLevel[id][57] = 26;
                    intraLevel[id][33] = 1;
                    intraLevel[id][45] = 2;
                    intraLevel[id][55] = 3;
                }
                #endregion
            }
            if (intraRun[id] == null)
            {
                intraRun[id] = new int[60];
                #region id == 0
                if (id == 0)
                {
                    intraRun[id][0] = 0;
                    intraRun[id][2] = 1;
                    intraRun[id][4] = 2;
                    intraRun[id][6] = 3;
                    intraRun[id][8] = 4;
                    intraRun[id][10] = 5;
                    intraRun[id][12] = 6;
                    intraRun[id][14] = 7;
                    intraRun[id][16] = 8;
                    intraRun[id][18] = 9;
                    intraRun[id][20] = 10;
                    intraRun[id][24] = 11;
                    intraRun[id][26] = 12;
                    intraRun[id][28] = 13;
                    intraRun[id][30] = 14;
                    intraRun[id][34] = 15;
                    intraRun[id][36] = 16;
                    intraRun[id][40] = 17;
                    intraRun[id][42] = 18;
                    intraRun[id][46] = 19;
                    intraRun[id][48] = 20;
                    intraRun[id][52] = 21;
                    intraRun[id][56] = 22;
                    intraRun[id][22] = 0;
                    intraRun[id][32] = 1;
                    intraRun[id][44] = 2;
                    intraRun[id][50] = 3;
                    intraRun[id][54] = 4;
                    intraRun[id][38] = 0;
                }
                #endregion
                #region id == 1
                if (id == 1)
                {
                    intraRun[id][0] = 0;
                    intraRun[id][2] = 1;
                    intraRun[id][6] = 2;
                    intraRun[id][9] = 3;
                    intraRun[id][11] = 4;
                    intraRun[id][13] = 5;
                    intraRun[id][19] = 6;
                    intraRun[id][21] = 7;
                    intraRun[id][23] = 8;
                    intraRun[id][29] = 9;
                    intraRun[id][31] = 10;
                    intraRun[id][37] = 11;
                    intraRun[id][43] = 12;
                    intraRun[id][47] = 13;
                    intraRun[id][57] = 14;
                    intraRun[id][4] = 0;
                    intraRun[id][17] = 1;
                    intraRun[id][25] = 2;
                    intraRun[id][33] = 3;
                    intraRun[id][39] = 4;
                    intraRun[id][45] = 5;
                    intraRun[id][49] = 6;
                    intraRun[id][51] = 7;
                    intraRun[id][15] = 0;
                    intraRun[id][35] = 1;
                    intraRun[id][53] = 2;
                    intraRun[id][27] = 0;
                    intraRun[id][41] = 0;
                    intraRun[id][55] = 0;
                }
                #endregion
                #region id == 2
                if (id == 2)
                {
                    intraRun[id][0] = 0;
                    intraRun[id][2] = 0;
                    intraRun[id][6] = 0;
                    intraRun[id][13] = 0;
                    intraRun[id][17] = 0;
                    intraRun[id][27] = 0;
                    intraRun[id][35] = 0;
                    intraRun[id][45] = 0;
                    intraRun[id][55] = 0;
                    intraRun[id][4] = 1;
                    intraRun[id][11] = 1;
                    intraRun[id][21] = 1;
                    intraRun[id][33] = 1;
                    intraRun[id][49] = 1;
                    intraRun[id][9] = 2;
                    intraRun[id][23] = 2;
                    intraRun[id][37] = 2;
                    intraRun[id][15] = 3;
                    intraRun[id][29] = 3;
                    intraRun[id][51] = 3;
                    intraRun[id][19] = 4;
                    intraRun[id][39] = 4;
                    intraRun[id][25] = 5;
                    intraRun[id][43] = 5;
                    intraRun[id][31] = 6;
                    intraRun[id][53] = 6;
                    intraRun[id][41] = 7;
                    intraRun[id][47] = 8;
                    intraRun[id][57] = 9;
                }
                #endregion
                #region id == 3
                if (id == 3)
                {
                    intraRun[id][0] = 0;
                    intraRun[id][2] = 0;
                    intraRun[id][4] = 0;
                    intraRun[id][9] = 0;
                    intraRun[id][11] = 0;
                    intraRun[id][17] = 0;
                    intraRun[id][21] = 0;
                    intraRun[id][25] = 0;
                    intraRun[id][33] = 0;
                    intraRun[id][39] = 0;
                    intraRun[id][45] = 0;
                    intraRun[id][55] = 0;
                    intraRun[id][6] = 1;
                    intraRun[id][13] = 1;
                    intraRun[id][19] = 1;
                    intraRun[id][29] = 1;
                    intraRun[id][35] = 1;
                    intraRun[id][47] = 1;
                    intraRun[id][15] = 2;
                    intraRun[id][27] = 2;
                    intraRun[id][41] = 2;
                    intraRun[id][57] = 2;
                    intraRun[id][23] = 3;
                    intraRun[id][37] = 3;
                    intraRun[id][53] = 3;
                    intraRun[id][31] = 4;
                    intraRun[id][51] = 4;
                    intraRun[id][43] = 5;
                    intraRun[id][49] = 6;
                }
                #endregion
                #region id == 4
                if (id == 4)
                {
                    intraRun[id][0] = 0;
                    intraRun[id][2] = 0;
                    intraRun[id][4] = 0;
                    intraRun[id][7] = 0;
                    intraRun[id][9] = 0;
                    intraRun[id][11] = 0;
                    intraRun[id][15] = 0;
                    intraRun[id][17] = 0;
                    intraRun[id][21] = 0;
                    intraRun[id][23] = 0;
                    intraRun[id][29] = 0;
                    intraRun[id][33] = 0;
                    intraRun[id][35] = 0;
                    intraRun[id][43] = 0;
                    intraRun[id][47] = 0;
                    intraRun[id][49] = 0;
                    intraRun[id][57] = 0;
                    intraRun[id][13] = 1;
                    intraRun[id][19] = 1;
                    intraRun[id][27] = 1;
                    intraRun[id][31] = 1;
                    intraRun[id][37] = 1;
                    intraRun[id][45] = 1;
                    intraRun[id][55] = 1;
                    intraRun[id][25] = 2;
                    intraRun[id][41] = 2;
                    intraRun[id][51] = 2;
                    intraRun[id][39] = 3;
                    intraRun[id][53] = 4;
                }
                #endregion
                #region id == 5
                if (id == 5)
                {
                    intraRun[id][1] = 0;
                    intraRun[id][3] = 0;
                    intraRun[id][5] = 0;
                    intraRun[id][7] = 0;
                    intraRun[id][9] = 0;
                    intraRun[id][11] = 0;
                    intraRun[id][13] = 0;
                    intraRun[id][15] = 0;
                    intraRun[id][17] = 0;
                    intraRun[id][19] = 0;
                    intraRun[id][23] = 0;
                    intraRun[id][25] = 0;
                    intraRun[id][27] = 0;
                    intraRun[id][31] = 0;
                    intraRun[id][33] = 0;
                    intraRun[id][37] = 0;
                    intraRun[id][41] = 0;
                    intraRun[id][45] = 0;
                    intraRun[id][49] = 0;
                    intraRun[id][51] = 0;
                    intraRun[id][55] = 0;
                    intraRun[id][21] = 1;
                    intraRun[id][29] = 1;
                    intraRun[id][35] = 1;
                    intraRun[id][43] = 1;
                    intraRun[id][47] = 1;
                    intraRun[id][53] = 1;
                    intraRun[id][39] = 2;
                    intraRun[id][57] = 2;
                }
                #endregion
                #region id == 6
                if (id == 6)
                {
                    intraRun[id][1] = 0;
                    intraRun[id][3] = 0;
                    intraRun[id][5] = 0;
                    intraRun[id][7] = 0;
                    intraRun[id][9] = 0;
                    intraRun[id][11] = 0;
                    intraRun[id][13] = 0;
                    intraRun[id][15] = 0;
                    intraRun[id][17] = 0;
                    intraRun[id][19] = 0;
                    intraRun[id][21] = 0;
                    intraRun[id][23] = 0;
                    intraRun[id][25] = 0;
                    intraRun[id][27] = 0;
                    intraRun[id][29] = 0;
                    intraRun[id][31] = 0;
                    intraRun[id][35] = 0;
                    intraRun[id][37] = 0;
                    intraRun[id][39] = 0;
                    intraRun[id][41] = 0;
                    intraRun[id][43] = 0;
                    intraRun[id][47] = 0;
                    intraRun[id][49] = 0;
                    intraRun[id][51] = 0;
                    intraRun[id][53] = 0;
                    intraRun[id][57] = 0;
                    intraRun[id][33] = 1;
                    intraRun[id][45] = 1;
                    intraRun[id][55] = 1;
                }
                #endregion
            }
            level = intraLevel[id];
            run = intraRun[id];
        }

        void UpdateInter()
        {
            if (interLevel == null)
                interLevel = new int[7][];
            if (interRun == null)
                interRun = new int[7][];
            if (interLevel[id] == null)
            {
                interLevel[id] = new int[60];
                #region id == 0
                if (id == 0)
                {
                    interLevel[id][0] = 1;
                    interLevel[id][2] = 1;
                    interLevel[id][4] = 1;
                    interLevel[id][6] = 1;
                    interLevel[id][8] = 1;
                    interLevel[id][10] = 1;
                    interLevel[id][12] = 1;
                    interLevel[id][14] = 1;
                    interLevel[id][16] = 1;
                    interLevel[id][18] = 1;
                    interLevel[id][20] = 1;
                    interLevel[id][22] = 1;
                    interLevel[id][24] = 1;
                    interLevel[id][28] = 1;
                    interLevel[id][30] = 1;
                    interLevel[id][32] = 1;
                    interLevel[id][34] = 1;
                    interLevel[id][36] = 1;
                    interLevel[id][38] = 1;
                    interLevel[id][42] = 1;
                    interLevel[id][44] = 1;
                    interLevel[id][48] = 1;
                    interLevel[id][50] = 1;
                    interLevel[id][52] = 1;
                    interLevel[id][54] = 1;
                    interLevel[id][56] = 1;
                    interLevel[id][26] = 2;
                    interLevel[id][46] = 2;
                    interLevel[id][40] = 3;
                }
                #endregion
                #region id == 1
                if (id == 1)
                {
                    interLevel[id][0] = 1;
                    interLevel[id][3] = 1;
                    interLevel[id][5] = 1;
                    interLevel[id][7] = 1;
                    interLevel[id][9] = 1;
                    interLevel[id][11] = 1;
                    interLevel[id][15] = 1;
                    interLevel[id][17] = 1;
                    interLevel[id][19] = 1;
                    interLevel[id][21] = 1;
                    interLevel[id][25] = 1;
                    interLevel[id][27] = 1;
                    interLevel[id][31] = 1;
                    interLevel[id][33] = 1;
                    interLevel[id][37] = 1;
                    interLevel[id][41] = 1;
                    interLevel[id][45] = 1;
                    interLevel[id][51] = 1;
                    interLevel[id][53] = 1;
                    interLevel[id][13] = 2;
                    interLevel[id][23] = 2;
                    interLevel[id][35] = 2;
                    interLevel[id][39] = 2;
                    interLevel[id][43] = 2;
                    interLevel[id][49] = 2;
                    interLevel[id][55] = 2;
                    interLevel[id][29] = 3;
                    interLevel[id][57] = 3;
                    interLevel[id][47] = 4;
                }
                #endregion
                #region id == 2
                if (id == 2)
                {
                    interLevel[id][0] = 1;
                    interLevel[id][3] = 1;
                    interLevel[id][7] = 1;
                    interLevel[id][9] = 1;
                    interLevel[id][15] = 1;
                    interLevel[id][17] = 1;
                    interLevel[id][19] = 1;
                    interLevel[id][25] = 1;
                    interLevel[id][31] = 1;
                    interLevel[id][33] = 1;
                    interLevel[id][39] = 1;
                    interLevel[id][43] = 1;
                    interLevel[id][51] = 1;
                    interLevel[id][57] = 1;
                    interLevel[id][5] = 2;
                    interLevel[id][13] = 2;
                    interLevel[id][21] = 2;
                    interLevel[id][29] = 2;
                    interLevel[id][37] = 2;
                    interLevel[id][41] = 2;
                    interLevel[id][53] = 2;
                    interLevel[id][11] = 3;
                    interLevel[id][27] = 3;
                    interLevel[id][45] = 3;
                    interLevel[id][55] = 3;
                    interLevel[id][23] = 4;
                    interLevel[id][49] = 4;
                    interLevel[id][35] = 5;
                    interLevel[id][47] = 6;
                }
                #endregion
                #region id == 3
                if (id == 3)
                {
                    interLevel[id][0] = 1;
                    interLevel[id][3] = 2;
                    interLevel[id][7] = 3;
                    interLevel[id][13] = 4;
                    interLevel[id][17] = 5;
                    interLevel[id][27] = 6;
                    interLevel[id][35] = 7;
                    interLevel[id][43] = 8;
                    interLevel[id][55] = 9;
                    interLevel[id][5] = 1;
                    interLevel[id][11] = 2;
                    interLevel[id][21] = 3;
                    interLevel[id][33] = 4;
                    interLevel[id][51] = 5;
                    interLevel[id][9] = 1;
                    interLevel[id][23] = 2;
                    interLevel[id][37] = 3;
                    interLevel[id][57] = 4;
                    interLevel[id][15] = 1;
                    interLevel[id][29] = 2;
                    interLevel[id][47] = 3;
                    interLevel[id][19] = 1;
                    interLevel[id][41] = 2;
                    interLevel[id][25] = 1;
                    interLevel[id][49] = 2;
                    interLevel[id][31] = 1;
                    interLevel[id][39] = 1;
                    interLevel[id][45] = 1;
                    interLevel[id][53] = 1;
                }
                #endregion
                #region id == 4
                if (id == 4)
                {
                    interLevel[id][0] = 1;
                    interLevel[id][3] = 2;
                    interLevel[id][5] = 3;
                    interLevel[id][9] = 4;
                    interLevel[id][11] = 5;
                    interLevel[id][17] = 6;
                    interLevel[id][21] = 7;
                    interLevel[id][25] = 8;
                    interLevel[id][33] = 9;
                    interLevel[id][41] = 10;
                    interLevel[id][45] = 11;
                    interLevel[id][55] = 12;
                    interLevel[id][7] = 1;
                    interLevel[id][13] = 2;
                    interLevel[id][19] = 3;
                    interLevel[id][29] = 4;
                    interLevel[id][35] = 5;
                    interLevel[id][49] = 6;
                    interLevel[id][15] = 1;
                    interLevel[id][27] = 2;
                    interLevel[id][43] = 3;
                    interLevel[id][57] = 4;
                    interLevel[id][23] = 1;
                    interLevel[id][37] = 2;
                    interLevel[id][51] = 3;
                    interLevel[id][31] = 1;
                    interLevel[id][53] = 2;
                    interLevel[id][39] = 1;
                    interLevel[id][47] = 1;
                }
                #endregion
                #region id == 5
                if (id == 5)
                {
                    interLevel[id][1] = 1;
                    interLevel[id][3] = 2;
                    interLevel[id][5] = 3;
                    interLevel[id][7] = 4;
                    interLevel[id][9] = 5;
                    interLevel[id][13] = 6;
                    interLevel[id][15] = 7;
                    interLevel[id][17] = 8;
                    interLevel[id][21] = 9;
                    interLevel[id][25] = 10;
                    interLevel[id][29] = 11;
                    interLevel[id][33] = 12;
                    interLevel[id][39] = 13;
                    interLevel[id][43] = 14;
                    interLevel[id][49] = 15;
                    interLevel[id][53] = 16;
                    interLevel[id][11] = 1;
                    interLevel[id][19] = 2;
                    interLevel[id][27] = 3;
                    interLevel[id][31] = 4;
                    interLevel[id][41] = 5;
                    interLevel[id][45] = 6;
                    interLevel[id][57] = 7;
                    interLevel[id][23] = 1;
                    interLevel[id][37] = 2;
                    interLevel[id][51] = 3;
                    interLevel[id][35] = 1;
                    interLevel[id][55] = 2;
                    interLevel[id][47] = 1;
                }
                #endregion
                #region id == 6
                if (id == 6)
                {
                    interLevel[id][1] = 1;
                    interLevel[id][3] = 2;
                    interLevel[id][5] = 3;
                    interLevel[id][7] = 4;
                    interLevel[id][9] = 5;
                    interLevel[id][11] = 6;
                    interLevel[id][13] = 7;
                    interLevel[id][17] = 8;
                    interLevel[id][19] = 9;
                    interLevel[id][21] = 10;
                    interLevel[id][23] = 11;
                    interLevel[id][25] = 12;
                    interLevel[id][29] = 13;
                    interLevel[id][33] = 14;
                    interLevel[id][35] = 15;
                    interLevel[id][39] = 16;
                    interLevel[id][41] = 17;
                    interLevel[id][43] = 18;
                    interLevel[id][47] = 19;
                    interLevel[id][49] = 20;
                    interLevel[id][57] = 21;
                    interLevel[id][15] = 1;
                    interLevel[id][27] = 2;
                    interLevel[id][37] = 3;
                    interLevel[id][45] = 4;
                    interLevel[id][55] = 5;
                    interLevel[id][31] = 1;
                    interLevel[id][51] = 2;
                    interLevel[id][53] = 1;
                }
                #endregion
            }
            if (interRun[id] == null)
            {
                interRun[id] = new int[60];
                #region id == 0
                if (id == 0)
                {
                    interRun[id][0] = 0;
                    interRun[id][2] = 1;
                    interRun[id][4] = 2;
                    interRun[id][6] = 3;
                    interRun[id][8] = 4;
                    interRun[id][10] = 5;
                    interRun[id][12] = 6;
                    interRun[id][14] = 7;
                    interRun[id][16] = 8;
                    interRun[id][18] = 9;
                    interRun[id][20] = 10;
                    interRun[id][22] = 11;
                    interRun[id][24] = 12;
                    interRun[id][28] = 13;
                    interRun[id][30] = 14;
                    interRun[id][32] = 15;
                    interRun[id][34] = 16;
                    interRun[id][36] = 17;
                    interRun[id][38] = 18;
                    interRun[id][42] = 19;
                    interRun[id][44] = 20;
                    interRun[id][48] = 21;
                    interRun[id][50] = 22;
                    interRun[id][52] = 23;
                    interRun[id][54] = 24;
                    interRun[id][56] = 25;
                    interRun[id][26] = 0;
                    interRun[id][46] = 1;
                    interRun[id][40] = 0;
                }
                #endregion
                #region id == 1
                if (id == 1)
                {
                    interRun[id][0] = 0;
                    interRun[id][3] = 1;
                    interRun[id][5] = 2;
                    interRun[id][7] = 3;
                    interRun[id][9] = 4;
                    interRun[id][11] = 5;
                    interRun[id][15] = 6;
                    interRun[id][17] = 7;
                    interRun[id][19] = 8;
                    interRun[id][21] = 9;
                    interRun[id][25] = 10;
                    interRun[id][27] = 11;
                    interRun[id][31] = 12;
                    interRun[id][33] = 13;
                    interRun[id][37] = 14;
                    interRun[id][41] = 15;
                    interRun[id][45] = 16;
                    interRun[id][51] = 17;
                    interRun[id][53] = 18;
                    interRun[id][13] = 0;
                    interRun[id][23] = 1;
                    interRun[id][35] = 2;
                    interRun[id][39] = 3;
                    interRun[id][43] = 4;
                    interRun[id][49] = 5;
                    interRun[id][55] = 6;
                    interRun[id][29] = 0;
                    interRun[id][57] = 1;
                    interRun[id][47] = 0;
                }
                #endregion
                #region id == 2
                if (id == 2)
                {
                    interRun[id][0] = 0;
                    interRun[id][3] = 1;
                    interRun[id][7] = 2;
                    interRun[id][9] = 3;
                    interRun[id][15] = 4;
                    interRun[id][17] = 5;
                    interRun[id][19] = 6;
                    interRun[id][25] = 7;
                    interRun[id][31] = 8;
                    interRun[id][33] = 9;
                    interRun[id][39] = 10;
                    interRun[id][43] = 11;
                    interRun[id][51] = 12;
                    interRun[id][57] = 13;
                    interRun[id][5] = 0;
                    interRun[id][13] = 1;
                    interRun[id][21] = 2;
                    interRun[id][29] = 3;
                    interRun[id][37] = 4;
                    interRun[id][41] = 5;
                    interRun[id][53] = 6;
                    interRun[id][11] = 0;
                    interRun[id][27] = 1;
                    interRun[id][45] = 2;
                    interRun[id][55] = 3;
                    interRun[id][23] = 0;
                    interRun[id][49] = 1;
                    interRun[id][35] = 0;
                    interRun[id][47] = 0;
                }
                #endregion
                #region id == 3
                if (id == 3)
                {
                    interRun[id][0] = 0;
                    interRun[id][3] = 0;
                    interRun[id][7] = 0;
                    interRun[id][13] = 0;
                    interRun[id][17] = 0;
                    interRun[id][27] = 0;
                    interRun[id][35] = 0;
                    interRun[id][43] = 0;
                    interRun[id][55] = 0;
                    interRun[id][5] = 1;
                    interRun[id][11] = 1;
                    interRun[id][21] = 1;
                    interRun[id][33] = 1;
                    interRun[id][51] = 1;
                    interRun[id][9] = 2;
                    interRun[id][23] = 2;
                    interRun[id][37] = 2;
                    interRun[id][57] = 2;
                    interRun[id][15] = 3;
                    interRun[id][29] = 3;
                    interRun[id][47] = 3;
                    interRun[id][19] = 4;
                    interRun[id][41] = 4;
                    interRun[id][25] = 5;
                    interRun[id][49] = 5;
                    interRun[id][31] = 6;
                    interRun[id][39] = 7;
                    interRun[id][45] = 8;
                    interRun[id][53] = 9;
                }
                #endregion
                #region id == 4
                if (id == 4)
                {
                    interRun[id][0] = 0;
                    interRun[id][3] = 0;
                    interRun[id][5] = 0;
                    interRun[id][9] = 0;
                    interRun[id][11] = 0;
                    interRun[id][17] = 0;
                    interRun[id][21] = 0;
                    interRun[id][25] = 0;
                    interRun[id][33] = 0;
                    interRun[id][41] = 0;
                    interRun[id][45] = 0;
                    interRun[id][55] = 0;
                    interRun[id][7] = 1;
                    interRun[id][13] = 1;
                    interRun[id][19] = 1;
                    interRun[id][29] = 1;
                    interRun[id][35] = 1;
                    interRun[id][49] = 1;
                    interRun[id][15] = 2;
                    interRun[id][27] = 2;
                    interRun[id][43] = 2;
                    interRun[id][57] = 2;
                    interRun[id][23] = 3;
                    interRun[id][37] = 3;
                    interRun[id][51] = 3;
                    interRun[id][31] = 4;
                    interRun[id][53] = 4;
                    interRun[id][39] = 5;
                    interRun[id][47] = 6;
                }
                #endregion
                #region id == 5
                if (id == 5)
                {
                    interRun[id][1] = 0;
                    interRun[id][3] = 0;
                    interRun[id][5] = 0;
                    interRun[id][7] = 0;
                    interRun[id][9] = 0;
                    interRun[id][13] = 0;
                    interRun[id][15] = 0;
                    interRun[id][17] = 0;
                    interRun[id][21] = 0;
                    interRun[id][25] = 0;
                    interRun[id][29] = 0;
                    interRun[id][33] = 0;
                    interRun[id][39] = 0;
                    interRun[id][43] = 0;
                    interRun[id][49] = 0;
                    interRun[id][53] = 0;
                    interRun[id][11] = 1;
                    interRun[id][19] = 1;
                    interRun[id][27] = 1;
                    interRun[id][31] = 1;
                    interRun[id][41] = 1;
                    interRun[id][45] = 1;
                    interRun[id][57] = 1;
                    interRun[id][23] = 2;
                    interRun[id][37] = 2;
                    interRun[id][51] = 2;
                    interRun[id][35] = 3;
                    interRun[id][55] = 3;
                    interRun[id][47] = 4;
                }
                #endregion
                #region id == 6
                if (id == 6)
                {
                    interRun[id][1] = 0;
                    interRun[id][3] = 0;
                    interRun[id][5] = 0;
                    interRun[id][7] = 0;
                    interRun[id][9] = 0;
                    interRun[id][11] = 0;
                    interRun[id][13] = 0;
                    interRun[id][17] = 0;
                    interRun[id][19] = 0;
                    interRun[id][21] = 0;
                    interRun[id][23] = 0;
                    interRun[id][25] = 0;
                    interRun[id][29] = 0;
                    interRun[id][33] = 0;
                    interRun[id][35] = 0;
                    interRun[id][39] = 0;
                    interRun[id][41] = 0;
                    interRun[id][43] = 0;
                    interRun[id][47] = 0;
                    interRun[id][49] = 0;
                    interRun[id][57] = 0;
                    interRun[id][15] = 1;
                    interRun[id][27] = 1;
                    interRun[id][37] = 1;
                    interRun[id][45] = 1;
                    interRun[id][55] = 1;
                    interRun[id][31] = 2;
                    interRun[id][51] = 2;
                    interRun[id][53] = 3;
                }
                #endregion
            }
            level = interLevel[id];
            run = interRun[id];
        }

        void UpdateChroma()
        {
            if (chromaLevel == null)
                chromaLevel = new int[5][];
            if (chromaRun == null)
                chromaRun = new int[5][];
            if (chromaLevel[id] == null)
            {
                chromaLevel[id] = new int[60];
                #region id == 0
                if (id == 0)
                {
                    chromaLevel[id][0] = 1;
                    chromaLevel[id][2] = 1;
                    chromaLevel[id][4] = 1;
                    chromaLevel[id][6] = 1;
                    chromaLevel[id][8] = 1;
                    chromaLevel[id][10] = 1;
                    chromaLevel[id][12] = 1;
                    chromaLevel[id][16] = 1;
                    chromaLevel[id][18] = 1;
                    chromaLevel[id][20] = 1;
                    chromaLevel[id][22] = 1;
                    chromaLevel[id][24] = 1;
                    chromaLevel[id][26] = 1;
                    chromaLevel[id][28] = 1;
                    chromaLevel[id][30] = 1;
                    chromaLevel[id][34] = 1;
                    chromaLevel[id][36] = 1;
                    chromaLevel[id][38] = 1;
                    chromaLevel[id][40] = 1;
                    chromaLevel[id][42] = 1;
                    chromaLevel[id][44] = 1;
                    chromaLevel[id][46] = 1;
                    chromaLevel[id][50] = 1;
                    chromaLevel[id][52] = 1;
                    chromaLevel[id][54] = 1;
                    chromaLevel[id][14] = 2;
                    chromaLevel[id][48] = 2;
                    chromaLevel[id][32] = 3;
                    chromaLevel[id][56] = 4;
                }
                #endregion
                #region id == 1
                if (id == 1)
                {
                    chromaLevel[id][1] = 1;
                    chromaLevel[id][3] = 1;
                    chromaLevel[id][7] = 1;
                    chromaLevel[id][9] = 1;
                    chromaLevel[id][11] = 1;
                    chromaLevel[id][13] = 1;
                    chromaLevel[id][17] = 1;
                    chromaLevel[id][19] = 1;
                    chromaLevel[id][23] = 1;
                    chromaLevel[id][25] = 1;
                    chromaLevel[id][27] = 1;
                    chromaLevel[id][31] = 1;
                    chromaLevel[id][33] = 1;
                    chromaLevel[id][35] = 1;
                    chromaLevel[id][39] = 1;
                    chromaLevel[id][47] = 1;
                    chromaLevel[id][49] = 1;
                    chromaLevel[id][51] = 1;
                    chromaLevel[id][55] = 1;
                    chromaLevel[id][57] = 1;
                    chromaLevel[id][5] = 2;
                    chromaLevel[id][21] = 2;
                    chromaLevel[id][37] = 2;
                    chromaLevel[id][41] = 2;
                    chromaLevel[id][53] = 2;
                    chromaLevel[id][15] = 3;
                    chromaLevel[id][45] = 3;
                    chromaLevel[id][29] = 4;
                    chromaLevel[id][43] = 5;
                }
                #endregion
                #region id == 2
                if (id == 2)
                {
                    chromaLevel[id][0] = 1;
                    chromaLevel[id][5] = 1;
                    chromaLevel[id][9] = 1;
                    chromaLevel[id][15] = 1;
                    chromaLevel[id][19] = 1;
                    chromaLevel[id][25] = 1;
                    chromaLevel[id][29] = 1;
                    chromaLevel[id][35] = 1;
                    chromaLevel[id][39] = 1;
                    chromaLevel[id][49] = 1;
                    chromaLevel[id][51] = 1;
                    chromaLevel[id][3] = 2;
                    chromaLevel[id][13] = 2;
                    chromaLevel[id][23] = 2;
                    chromaLevel[id][31] = 2;
                    chromaLevel[id][43] = 2;
                    chromaLevel[id][45] = 2;
                    chromaLevel[id][7] = 3;
                    chromaLevel[id][21] = 3;
                    chromaLevel[id][41] = 3;
                    chromaLevel[id][57] = 3;
                    chromaLevel[id][11] = 4;
                    chromaLevel[id][37] = 4;
                    chromaLevel[id][17] = 5;
                    chromaLevel[id][55] = 5;
                    chromaLevel[id][27] = 6;
                    chromaLevel[id][33] = 7;
                    chromaLevel[id][47] = 8;
                    chromaLevel[id][53] = 9;
                }
                #endregion
                #region id == 3
                if (id == 3)
                {
                    chromaLevel[id][1] = 1;
                    chromaLevel[id][3] = 2;
                    chromaLevel[id][5] = 3;
                    chromaLevel[id][7] = 4;
                    chromaLevel[id][11] = 5;
                    chromaLevel[id][15] = 6;
                    chromaLevel[id][19] = 7;
                    chromaLevel[id][23] = 8;
                    chromaLevel[id][29] = 9;
                    chromaLevel[id][35] = 10;
                    chromaLevel[id][43] = 11;
                    chromaLevel[id][47] = 12;
                    chromaLevel[id][53] = 13;
                    chromaLevel[id][9] = 1;
                    chromaLevel[id][13] = 2;
                    chromaLevel[id][21] = 3;
                    chromaLevel[id][31] = 4;
                    chromaLevel[id][39] = 5;
                    chromaLevel[id][51] = 6;
                    chromaLevel[id][17] = 1;
                    chromaLevel[id][27] = 2;
                    chromaLevel[id][37] = 3;
                    chromaLevel[id][25] = 1;
                    chromaLevel[id][41] = 2;
                    chromaLevel[id][33] = 1;
                    chromaLevel[id][55] = 2;
                    chromaLevel[id][45] = 1;
                    chromaLevel[id][49] = 1;
                    chromaLevel[id][57] = 1;
                }
                #endregion
                #region id == 4
                if (id == 4)
                {
                    chromaLevel[id][1] = 1;
                    chromaLevel[id][3] = 2;
                    chromaLevel[id][5] = 3;
                    chromaLevel[id][7] = 4;
                    chromaLevel[id][9] = 5;
                    chromaLevel[id][11] = 6;
                    chromaLevel[id][13] = 7;
                    chromaLevel[id][15] = 8;
                    chromaLevel[id][19] = 9;
                    chromaLevel[id][21] = 10;
                    chromaLevel[id][23] = 11;
                    chromaLevel[id][27] = 12;
                    chromaLevel[id][29] = 13;
                    chromaLevel[id][33] = 14;
                    chromaLevel[id][37] = 15;
                    chromaLevel[id][41] = 16;
                    chromaLevel[id][43] = 17;
                    chromaLevel[id][51] = 18;
                    chromaLevel[id][55] = 19;
                    chromaLevel[id][17] = 1;
                    chromaLevel[id][25] = 2;
                    chromaLevel[id][31] = 3;
                    chromaLevel[id][39] = 4;
                    chromaLevel[id][45] = 5;
                    chromaLevel[id][53] = 6;
                    chromaLevel[id][35] = 1;
                    chromaLevel[id][49] = 2;
                    chromaLevel[id][47] = 1;
                    chromaLevel[id][57] = 1;
                }
                #endregion
            }
            if (chromaRun[id] == null)
            {
                chromaRun[id] = new int[60];
                #region id == 0
                if (id == 0)
                {
                    chromaRun[id][0] = 0;
                    chromaRun[id][2] = 1;
                    chromaRun[id][4] = 2;
                    chromaRun[id][6] = 3;
                    chromaRun[id][8] = 4;
                    chromaRun[id][10] = 5;
                    chromaRun[id][12] = 6;
                    chromaRun[id][16] = 7;
                    chromaRun[id][18] = 8;
                    chromaRun[id][20] = 9;
                    chromaRun[id][22] = 10;
                    chromaRun[id][24] = 11;
                    chromaRun[id][26] = 12;
                    chromaRun[id][28] = 13;
                    chromaRun[id][30] = 14;
                    chromaRun[id][34] = 15;
                    chromaRun[id][36] = 16;
                    chromaRun[id][38] = 17;
                    chromaRun[id][40] = 18;
                    chromaRun[id][42] = 19;
                    chromaRun[id][44] = 20;
                    chromaRun[id][46] = 21;
                    chromaRun[id][50] = 22;
                    chromaRun[id][52] = 23;
                    chromaRun[id][54] = 24;
                    chromaRun[id][14] = 0;
                    chromaRun[id][48] = 1;
                    chromaRun[id][32] = 0;
                    chromaRun[id][56] = 0;
                }
                #endregion
                #region id == 1
                if (id == 1)
                {
                    chromaRun[id][1] = 0;
                    chromaRun[id][3] = 1;
                    chromaRun[id][7] = 2;
                    chromaRun[id][9] = 3;
                    chromaRun[id][11] = 4;
                    chromaRun[id][13] = 5;
                    chromaRun[id][17] = 6;
                    chromaRun[id][19] = 7;
                    chromaRun[id][23] = 8;
                    chromaRun[id][25] = 9;
                    chromaRun[id][27] = 10;
                    chromaRun[id][31] = 11;
                    chromaRun[id][33] = 12;
                    chromaRun[id][35] = 13;
                    chromaRun[id][39] = 14;
                    chromaRun[id][47] = 15;
                    chromaRun[id][49] = 16;
                    chromaRun[id][51] = 17;
                    chromaRun[id][55] = 18;
                    chromaRun[id][57] = 19;
                    chromaRun[id][5] = 0;
                    chromaRun[id][21] = 1;
                    chromaRun[id][37] = 2;
                    chromaRun[id][41] = 3;
                    chromaRun[id][53] = 4;
                    chromaRun[id][15] = 0;
                    chromaRun[id][45] = 1;
                    chromaRun[id][29] = 0;
                    chromaRun[id][43] = 0;
                }
                #endregion
                #region id == 2
                if (id == 2)
                {
                    chromaRun[id][0] = 0;
                    chromaRun[id][5] = 1;
                    chromaRun[id][9] = 2;
                    chromaRun[id][15] = 3;
                    chromaRun[id][19] = 4;
                    chromaRun[id][25] = 5;
                    chromaRun[id][29] = 6;
                    chromaRun[id][35] = 7;
                    chromaRun[id][39] = 8;
                    chromaRun[id][49] = 9;
                    chromaRun[id][51] = 10;
                    chromaRun[id][3] = 0;
                    chromaRun[id][13] = 1;
                    chromaRun[id][23] = 2;
                    chromaRun[id][31] = 3;
                    chromaRun[id][43] = 4;
                    chromaRun[id][45] = 5;
                    chromaRun[id][7] = 0;
                    chromaRun[id][21] = 1;
                    chromaRun[id][41] = 2;
                    chromaRun[id][57] = 3;
                    chromaRun[id][11] = 0;
                    chromaRun[id][37] = 1;
                    chromaRun[id][17] = 0;
                    chromaRun[id][55] = 1;
                    chromaRun[id][27] = 0;
                    chromaRun[id][33] = 0;
                    chromaRun[id][47] = 0;
                    chromaRun[id][53] = 0;
                }
                #endregion
                #region id == 3
                if (id == 3)
                {
                    chromaRun[id][1] = 0;
                    chromaRun[id][3] = 0;
                    chromaRun[id][5] = 0;
                    chromaRun[id][7] = 0;
                    chromaRun[id][11] = 0;
                    chromaRun[id][15] = 0;
                    chromaRun[id][19] = 0;
                    chromaRun[id][23] = 0;
                    chromaRun[id][29] = 0;
                    chromaRun[id][35] = 0;
                    chromaRun[id][43] = 0;
                    chromaRun[id][47] = 0;
                    chromaRun[id][53] = 0;
                    chromaRun[id][9] = 1;
                    chromaRun[id][13] = 1;
                    chromaRun[id][21] = 1;
                    chromaRun[id][31] = 1;
                    chromaRun[id][39] = 1;
                    chromaRun[id][51] = 1;
                    chromaRun[id][17] = 2;
                    chromaRun[id][27] = 2;
                    chromaRun[id][37] = 2;
                    chromaRun[id][25] = 3;
                    chromaRun[id][41] = 3;
                    chromaRun[id][33] = 4;
                    chromaRun[id][55] = 4;
                    chromaRun[id][45] = 5;
                    chromaRun[id][49] = 6;
                    chromaRun[id][57] = 7;
                }
                #endregion
                #region id == 4
                if (id == 4)
                {
                    chromaRun[id][1] = 0;
                    chromaRun[id][3] = 0;
                    chromaRun[id][5] = 0;
                    chromaRun[id][7] = 0;
                    chromaRun[id][9] = 0;
                    chromaRun[id][11] = 0;
                    chromaRun[id][13] = 0;
                    chromaRun[id][15] = 0;
                    chromaRun[id][19] = 0;
                    chromaRun[id][21] = 0;
                    chromaRun[id][23] = 0;
                    chromaRun[id][27] = 0;
                    chromaRun[id][29] = 0;
                    chromaRun[id][33] = 0;
                    chromaRun[id][37] = 0;
                    chromaRun[id][41] = 0;
                    chromaRun[id][43] = 0;
                    chromaRun[id][51] = 0;
                    chromaRun[id][55] = 0;
                    chromaRun[id][17] = 1;
                    chromaRun[id][25] = 1;
                    chromaRun[id][31] = 1;
                    chromaRun[id][39] = 1;
                    chromaRun[id][45] = 1;
                    chromaRun[id][53] = 1;
                    chromaRun[id][35] = 2;
                    chromaRun[id][49] = 2;
                    chromaRun[id][47] = 3;
                    chromaRun[id][57] = 4;
                }
                #endregion
            }
            level = chromaLevel[id];
            run = chromaRun[id];
        }
    }
}
